/** @type {import('next').NextConfig} */
const isProd = process.env.NODE_ENV === 'production'
console.log(process.env.NEXT_PUBLIC_CDN_URL)
const nextConfig = {
  reactStrictMode: false,
  transpilePackages: ['antd-mobile'],
  assetPrefix: process.env.NEXT_PUBLIC_BASE_PATH,
  basePath: process.env.NEXT_PUBLIC_BASE_PATH,
  sassOptions: {
    prependData: `$base_path: '${process.env.NEXT_PUBLIC_CDN_URL}';$font_base: '${process.env.NEXT_PUBLIC_FONT}/font';`,
    // prependData: `$base_path: '/car1008';`,
  },
  webpack: (config, {defaultLoaders}) => {
    // Process any JS outside of the app with Babel.
    // Unlike the application JS, we only compile the standard ES features.
    config.module.rules.push({
      test: /\.(js|mjs)$/,
      exclude: /@babel(?:\/|\\{1,2})runtime/,
      use: defaultLoaders.babel,
    });
    return config;
  },
  // async redirects() {
  //   return [
  //     {
  //       source: '/api/:path*',
  //       destination: '/:path*',
  //       permanent: false,
  //       basePath: false,
  //     },
  //     {
  //       source: '/auth/:path*',
  //       destination: '/:path*',
  //       permanent: false,
  //       basePath: false,
  //     }
  //   ]
  // },
  async rewrites() {
    return [
      {
        source: `/${process.env.NEXT_PUBLIC_API_PREFIX}/apx/:slug*`,
        destination: `${process.env.NEXT_PUBLIC_SERVER_BASE}/${process.env.NEXT_PUBLIC_API_PREFIX}/:slug*`,
        basePath: false,
      },

      {
        source: `${process.env.NEXT_PUBLIC_API_PREFIX}/:path*`,
        destination: `${process.env.NEXT_PUBLIC_SERVER_BASE}${process.env.NEXT_PUBLIC_API_PREFIX}/:path*`,
        basePath: false,

      }
    ]
  },
}

module.exports = nextConfig
